// part1:C10:ex10.17.cpp
// write compareIsbn, use lambda function.
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include "Sales_data.h"
using namespace std;

int main(int argc, char *argv[])
{
    ifstream in(argv[1]);
    if (!in) 
    {
        cout << "failed open input file!\n";
        exit(1);
    }

    vector<Sales_data> sds;
    Sales_data sd;
    while (read_record(in, sd)) 
    {
        sds.push_back(sd);    
    }

    sort(sds.begin(), sds.end(),
        [](const Sales_data &lhs, const Sales_data &rhs)
        { return lhs.isbn() < rhs.isbn(); });

     for (const auto &s : sds) 
     {
        print_record(cout, s);    
        cout << endl;
     }

    return 0;
}
